/* mvutils_mpi.h

   Include file for various mpi operations related to matrix-vector operations

   Basile Clout, September 2007

   From M. J. Quinn
   */


#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>

#define PRINT 1
#define TIME 1

/*Useful macros*/
/* WARNING: NO SPACE BETWEEN NAME AND PARAMETERS!!! */
#define BLOCK_LOW(r, p, n) ((r)*(n)/(p))
#define BLOCK_HIGH(r, p, n) (BLOCK_LOW(r+1, p, n) - 1)
#define BLOCK_SIZE(r, p, n) (BLOCK_HIGH(r, p, n) - BLOCK_LOW(r, p, n) + 1)



/* Read a matrix and scatter in the cluster*/
int mread(char *fn, double ***lmat, double **lar, int *m, int *n, MPI_Comm com, int rm);

/* Print a scattered matrix (using gatherv) */
int mprint(double **mat, int m, int n, MPI_Comm com, int rm);

/* Read a vector and scatter it (using MPI_send/recv) */
int vread(char *fn, double **subvec, int *n, MPI_Comm com, int rm);

/* Print a scattered vector (using gatherv, possible to use send/recv too ...) */
int vprint(double *v, int n, MPI_Comm com, int rm);

